package com.powerbank.common.client;

import com.powerbank.common.result.Result;
import com.powerbank.common.result.PageResult;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 设备中心服务客户端
 */
@FeignClient(name = "device-center", path = "/devices", fallback = DeviceCenterClientFallback.class)
public interface DeviceCenterClient {

    /**
     * 根据设备编码获取设备信息
     */
    @GetMapping("/{deviceCode}")
    Result<Map<String, Object>> getDeviceInfo(@PathVariable("deviceCode") String deviceCode);
    
    /**
     * 根据设备ID获取设备DTO
     */
    @GetMapping("/{deviceId}/dto")
    Result<com.powerbank.common.dto.DeviceDTO> getDeviceById(@PathVariable("deviceId") Long deviceId);

    /**
     * 检查设备状态
     */
    @GetMapping("/{deviceCode}/status")
    Result<Map<String, Object>> getDeviceStatus(@PathVariable("deviceCode") String deviceCode);

    /**
     * 获取设备可用槽位
     */
    @GetMapping("/{deviceCode}/slots/available")
    Result<List<Map<String, Object>>> getAvailableSlots(@PathVariable("deviceCode") String deviceCode);

    /**
     * 租借充电宝
     */
    @PostMapping("/{deviceCode}/rent")
    Result<Map<String, Object>> rentPowerbank(@PathVariable("deviceCode") String deviceCode,
                                             @RequestBody Map<String, Object> rentRequest);

    /**
     * 归还充电宝
     */
    @PostMapping("/{deviceCode}/return")
    Result<Map<String, Object>> returnPowerbank(@PathVariable("deviceCode") String deviceCode,
                                               @RequestBody Map<String, Object> returnRequest);

    /**
     * 搜索附近设备
     */
    @GetMapping("/nearby")
    Result<List<Map<String, Object>>> getNearbyDevices(@RequestParam("longitude") Double longitude,
                                                       @RequestParam("latitude") Double latitude,
                                                       @RequestParam(value = "radius", defaultValue = "1000") Integer radius);

    /**
     * 设备上线
     */
    @PostMapping("/{deviceCode}/online")
    Result<Void> deviceOnline(@PathVariable("deviceCode") String deviceCode);

    /**
     * 设备下线
     */
    @PostMapping("/{deviceCode}/offline")
    Result<Void> deviceOffline(@PathVariable("deviceCode") String deviceCode);

    /**
     * 更新设备状态
     */
    @PutMapping("/{deviceCode}/status")
    Result<Void> updateDeviceStatus(@PathVariable("deviceCode") String deviceCode,
                                   @RequestBody Map<String, Object> statusUpdate);

    /**
     * 获取设备列表
     */
    @GetMapping("/list")
    Result<PageResult<Map<String, Object>>> getDeviceList(@RequestParam("page") Integer page,
                                                          @RequestParam("size") Integer size,
                                                          @RequestParam(value = "keyword", required = false) String keyword,
                                                          @RequestParam(value = "status", required = false) Integer status);

    /**
     * 发送设备指令
     */
    @PostMapping("/{deviceCode}/command")
    Result<Void> sendDeviceCommand(@PathVariable("deviceCode") String deviceCode,
                                  @RequestBody Map<String, Object> command);

    /**
     * 获取设备运行数据
     */
    @GetMapping("/{deviceCode}/metrics")
    Result<Map<String, Object>> getDeviceMetrics(@PathVariable("deviceCode") String deviceCode);
    
    /**
     * 锁定设备
     */
    @PostMapping("/{deviceId}/lock")
    Result<Void> lockDevice(@PathVariable("deviceId") Long deviceId, @RequestParam("orderNo") String orderNo);
    
    /**
     * 解锁设备
     */
    @PostMapping("/{deviceId}/unlock")
    Result<Void> unlockDevice(@PathVariable("deviceId") Long deviceId, @RequestParam("orderNo") String orderNo);
}